<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录测试页面</title>
    <script src="js/auth.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .status {
            padding: 15px;
            margin: 20px 0;
            border-radius: 5px;
            font-weight: bold;
        }
        .success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        .error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        .info {
            background-color: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin: 5px;
        }
        button:hover {
            background-color: #0056b3;
        }
        .logout-btn {
            background-color: #dc3545;
        }
        .logout-btn:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body data-require-login="true">
    <div class="container">
        <h1>登录状态测试页面</h1>
        
        <div id="status" class="status info">
            正在检查登录状态...
        </div>
        
        <div id="userInfo" style="display: none;">
            <h3>用户信息</h3>
            <p>用户名: <span id="username"></span></p>
            <button class="logout-btn" onclick="logout()">退出登录</button>
        </div>
        
        <div id="loginInfo" style="display: none;">
            <h3>未登录</h3>
            <p>请先登录才能访问此页面</p>
            <button onclick="window.location.href='/login.html'">去登录</button>
        </div>
        
        <hr>
        
        <h3>测试功能</h3>
        <button onclick="testCheckLogin()">检查登录状态</button>
        <button onclick="testLogout()">测试退出登录</button>
        <button onclick="window.location.href='/first.html'">返回主页</button>
    </div>

    <script>
        // 页面加载时检查登录状态
        document.addEventListener('DOMContentLoaded', function() {
            checkLoginStatus().then(data => {
                const statusEl = document.getElementById('status');
                const userInfoEl = document.getElementById('userInfo');
                const loginInfoEl = document.getElementById('loginInfo');
                
                if (data.success && data.loggedIn) {
                    statusEl.className = 'status success';
                    statusEl.textContent = '登录状态: 已登录';
                    
                    userInfoEl.style.display = 'block';
                    loginInfoEl.style.display = 'none';
                    
                    document.getElementById('username').textContent = data.username;
                } else {
                    statusEl.className = 'status error';
                    statusEl.textContent = '登录状态: 未登录';
                    
                    userInfoEl.style.display = 'none';
                    loginInfoEl.style.display = 'block';
                }
            });
        });
        
        function testCheckLogin() {
            checkLoginStatus().then(data => {
                alert('登录状态检查结果: ' + JSON.stringify(data, null, 2));
            });
        }
        
        function testLogout() {
            if (confirm('确定要退出登录吗？')) {
                logout();
            }
        }
    </script>
</body>
</html> 